class Solution {
public:
    bool isHappy(int n) {
        while(n != 1){
            int a, sum = 0;
            while(n){
                a = n % 10;
                sum += a*a;
                n = n / 10;
            }
            n = sum;
            if(sum==4){
                return false;
            }
        }
        return true;
    }
};